package com.wfm.leetcode.editor.cn;

import com.wfm.common.ListNode;

/**
 * 为什么要加一个dummy节点是因为，为了适配只有一个节点的情况【1】1
 * 因为我们要找到待删除节点的前一个节点，所以如果节点个数为1，则需要加个dummy
 */
public class P剑指OfferII021删除链表的倒数第N个结点{
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode kthFromEnd = new BM8链表中倒数最后k个节点O22().getKthFromEnd(head,n + 1);
        kthFromEnd.next = kthFromEnd.next.next;
        return dummy.next;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) { 
        Solution solution = new P剑指OfferII021删除链表的倒数第N个结点().new Solution();
    }
}